package com.mx.zb.mng.utils;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.mx.zb.mng.utils.context.InterInterceptor;
import com.mx.zb.mng.utils.context.LoginInterceptor;
import com.mx.zb.mng.utils.context.LoginRestInterceptor;
import com.mx.zb.mng.utils.context.WxInterceptor;

@Configuration
public class WebConfig extends WebMvcConfigurerAdapter{
	
	@Value("${spring.resources.chain.strategy.fixed.version}")
	private String resourcesVersion;
	
	private LoginInterceptor loginInterceptor;
	
	private LoginRestInterceptor loginRestInterceptor;
	
	private WxInterceptor wxInterceptor;
	
	private InterInterceptor interInterceptor;
	
	@Bean
	  public LoginInterceptor userInterceptor() {
		loginInterceptor=new LoginInterceptor();
	    return loginInterceptor;
	  }
	
	@Bean
	  public LoginRestInterceptor userInterceptor2() {
		loginRestInterceptor=new LoginRestInterceptor();
	    return loginRestInterceptor;
	  }
	
	@Bean
	  public WxInterceptor userInterceptor3() {
		wxInterceptor=new WxInterceptor();
	    return wxInterceptor;
	  }
	
	@Bean
	  public InterInterceptor userInterceptor4() {
		interInterceptor=new InterInterceptor();
	    return interInterceptor;
	  }
	
	/**
     * 配置静态访问资源
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {    	
    	registry.addResourceHandler("/"+resourcesVersion+"/**").addResourceLocations("classpath:/static/");
        super.addResourceHandlers(registry);
    }
	
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截规则：除了login，其他都拦截判断
        registry.addInterceptor(loginInterceptor).addPathPatterns("/p/**");
        registry.addInterceptor(loginRestInterceptor).addPathPatterns("/a/**");
        registry.addInterceptor(wxInterceptor).addPathPatterns("/wx/**");
        registry.addInterceptor(interInterceptor).addPathPatterns("/i/**");
        //.excludePathPatterns("/adminUser/login");
        super.addInterceptors(registry);
    }
    
}
